package com.syxx.oa.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.syxx.oa.dao.PersonnelRequirementDao;
import com.syxx.oa.domain.PersonnelRequirement;
import com.syxx.oa.service.PersonnelRequirementService;
import com.test.jbpm.Pager;

@Service
public class PersonnelRequirementServiceImpl implements
		PersonnelRequirementService {

	private PersonnelRequirementDao personnelRequirementDao;
	
	@Autowired
	public void setPersonnelRequirementDao(
			PersonnelRequirementDao personnelRequirementDao) {
		this.personnelRequirementDao = personnelRequirementDao;
	}

	public void addOrUpdate(PersonnelRequirement perReq) {
		if(perReq==null){
			return;
		}
		if(perReq.get_id()== null || perReq.get_id()== 0){
			perReq.set_id(null);
			perReq.setCreateTime(new Date());
			perReq.setStatus(PersonnelRequirement.NEW);
		}
		personnelRequirementDao.addOrUpdate(perReq);
	}

	public void del(Long[] perReqIds) {
		for (Long _id : perReqIds) {
			personnelRequirementDao.del(_id);
		}

	}

	public PersonnelRequirement findPersonnelRequirementById(Long perReqId) {
		
		return personnelRequirementDao.findTroubleTicketById(perReqId);
	}

	public Pager<PersonnelRequirement> findMyPersonnelRequirementList(
			Long creatorId) {
		// TODO Auto-generated method stub
		return personnelRequirementDao.findMyPersonnelRequirementList(creatorId);
	}

	public void dispatch(Long[] perReqIds) {
		for (Long _id : perReqIds) {
			personnelRequirementDao.dispatch(_id);
		}

	}
 
	public Pager<PersonnelRequirement> findApprovingPersonnelRequirementList(
			Long approverId) {
		return personnelRequirementDao.findApprovingPersonnelRequirementList(approverId);
	}

	public Pager<PersonnelRequirement> findApprovedPersonnelRequirementList(
			Long approverId) {
		return personnelRequirementDao.findApprovedTroubleTicketList(approverId);
		 
	}

	
}
